package com.pj.hellomvvm.ui.activity

import android.os.Bundle
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.pj.common.base.BaseActivity
import com.pj.common.base.BaseViewModel
import com.pj.hellomvvm.R
import com.pj.hellomvvm.databinding.ActivityFragmentContainerBinding
import com.pj.hellomvvm.ui.fragment.other.OtherMMKVFragment
import com.pj.hellomvvm.ui.fragment.widget.PullLayoutRefreshLoadFragment
import com.pj.hellomvvm.ui.fragment.widget.WidgetButtonFragment


@Route(path = "/widget/WidgetActivity", group = "widget")
class WidgetActivity:BaseActivity<BaseViewModel,ActivityFragmentContainerBinding>() {
    //获取数据三种方式
    //1.通过Autowired注解表明key   &  需要在onCreate中调用ARouter.getInstance().inject(this);配合使用
    @Autowired
    lateinit var target: String
    override fun getLayoutRes(): Int {
        return R.layout.activity_fragment_container
    }

    override fun initData(savedInstanceState: Bundle?) {
        super.initData(savedInstanceState)
        ARouter.getInstance().inject(this)
        when (target) {
            "Button" -> {
                addFragment(WidgetButtonFragment())
            }
            "PullRefreshLoadLayout" -> {
                addFragment(PullLayoutRefreshLoadFragment())
            }
        }
    }

    private fun addFragment(fragment:Fragment){
        var transient = supportFragmentManager.beginTransaction()
        transient.add(R.id.frame_layout,fragment,target)
        transient.commit()
    }

}